package idv.cjcat.pyronova.nodes {
	import flash.display.BitmapData;
	import idv.cjcat.pyronova.render.Graphics;
	import idv.cjcat.pyronova.render.RenderVisitor;
	
	public class SetPixels extends Node {
		
		public var points:Vector.<int>;
		public var colors:Vector.<uint>;
		public var useAlpha:Boolean;
		
		public function SetPixels(points:Vector.<int> = null, colors:Vector.<uint> = null, useAlpha:Boolean = false) {
			this.points = points;
			this.colors = colors;
			this.useAlpha = useAlpha;
		}
		
		private var i:int, len:int;
		private var buffer:BitmapData;
		override public function render(visitor:RenderVisitor):void {
			buffer = visitor.graphics().topBuffer();
			if (useAlpha) {
				for (i = 0, len = points.length; i < len; ++i) {
					buffer.setPixel32(points[i], points[i + 1], colors[i]);
					++i;
				}
			} else {
				for (i = 0, len = points.length; i < len; ++i) {
					buffer.setPixel32(points[i], points[i + 1], colors[i] | 0xFF000000);
					++i;
				}
			}
		}
	}
}